package com.itheima.comfyui.core.service.impl;

import com.itheima.comfyui.core.service.OllamaService;
import com.itheima.comfyui.ollama.client.api.OllamaApi;
import com.itheima.comfyui.ollama.client.pojo.OllamaChatRequest;
import com.itheima.comfyui.ollama.client.pojo.OllamaChatRespone;
import com.itheima.comfyui.ollama.client.pojo.OllamaMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import retrofit2.Call;
import retrofit2.Response;

import java.io.IOException;
import java.util.List;
@Service
public class OllamaServiceImpl implements OllamaService {
    @Autowired
    private OllamaApi ollamaApi;

    @Override
    public String translate(String prompt) {

            OllamaChatRequest request = new OllamaChatRequest();
            request.setModel("qwen2:0.5b");
            OllamaMessage message = new OllamaMessage();
            message.setRole("user");
            message.setContent(String.format("请将下面的文本翻译成英文:\n%s",prompt));
            request.setMessages(List.of(message));
            Call<OllamaChatRespone> ollamaChatResponeCall = ollamaApi.chat(request);
            Response<OllamaChatRespone> execute = null;
        try {
            execute =ollamaChatResponeCall.execute();
            OllamaChatRespone body = execute.body();
            return body.getMessage().getContent();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return prompt;
    }

}
